import prisma from '~~/lib/prisma'
import Joi from 'joi'
import { Result } from '~~/lib/helper/result'
export default defineEventHandler(async (event) => {
  const userId = getLoginId(event)
  const body = await readBody(event)
  const schema = Joi.object({
    name: Joi.string().required(),
  })

  try {
    await schema.validateAsync(body)
  } catch (error) {
    return Result.Error('参数错误！')
  }
  try {
    await prisma.notebook.create({ data: { uid: userId, name: body.name } })
  } catch (error) {
    return Result.Error('创建文集失败！')
  }
  return Result.Ok(null, 200, '创建文集成功！')
})
